<template>
  <el-dialog :title="title" :visible="visible" @close="handleClose" width="800px">
    <el-form :model="formEdit" label-position="right" label-width="68px" ref="formRef">
      <el-form-item label="预警阈值" prop="warningTime">
        <el-input placeholder="请输入预警阈值" v-model="formEdit.warningTime"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="saveForm">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {
   updataWmsWarningType//修改天数
  } from '@/api/report/index.js'
  export default {
    data() {
      return {
        title: '修改预警信息',
        formEdit: {
          warningTime: ''
        },
      }
    },
    props: {
      visible: { // 接收父组件通过sync传递的visible属性
        type: Boolean,
        default: false
      }
    },
    methods: {
      openDialog(type,row) {
        // 根据类型区分新增和编辑逻辑
        if (type === 'edit' && row) {
          this.formEdit = {
            ...row
          };
        } else {
          this.formEdit = {
            warnDay:''
          }
        }
      },
      // 提取重置表单的逻辑
      handleClose() {
        // 通过事件通知父组件更新visible值，触发update:visible事件
        this.$nextTick(() => {
          this.$refs.formRef.resetFields();
        })
        this.$emit('update:visible', false);
      },
      //提交规则关联
      saveForm() {
        this.$refs.formRef.validate((valid) => {
          if (valid) {
            updataWmsWarningType(this.formEdit).then(res => {
              this.$emit('addSuccess'); // 通知父组件添加成功
              this.$message({
                message: res.msg, // 显示成功消息
                type: 'success',
              });
              this.handleClose();
            })
          }
        })
      },
    }
  }
</script>

<style>
</style>
